import {Service} from "adajs";

const MAP = ["局内转", "报人事局", "已批准", "已备案", "其他"];

class NewsService extends Service {
    defaultData() {
        return {
            isLoad: false,
            newsInfo: {
                applyTime: "2018-12-03 00:00:00",
                backDate: "2018-12-31 00:00:00",
                bmid: "1",
                crtIp: "127.0.0.1",
                crtTime: "2018-12-20 11:40:22",
                crtUser: "admin",
                destination: "1",
                goDate: "2018-12-05 00:00:00",
                gwid: "1",
                handleState: "1",
                handleqt: "",
                id: "15142a5a-02f9-455f-b9d3-b74277019852",
                jg: "东北",
                ltzbirthday: "1966-03-06 00:00:00",
                ltznl: "53岁",
                ltztlxlx: "退休",
                ltztlxzj: "正部级",
                ltzxm: "刘能",
                ltzydw: "铁岭TV",
                reason: "",
                reasonqt: "",
                sex: "男",
                sqrid: "1",
                ssdzb: "一支部",
                yhid: "1",
                zzid: "1",
                state: ""
            },
            id: "",
            error: false,
            msg: ""
        };
    }

    onupdate(current, id) {
        if (id) {
            return this.context.request.post("/api/lgb/app/lgb/abroad/get", {id}).then(({data, code, msg}) => {
                if (code === '1') {
                    return this.context.request.post("/api/lgb/app/sys/sysDictionary/getByDictCode", {dictCode: "reason"}).then(info => {
                        let target = info.data.find(a => a.id === data.reason);
                        if (target) {
                            data.reason = target.dictName;
                        }
                        return this.context.request.post("/api/lgb/app/sys/sysDictionary/getByDictCode", {dictCode: "bljdout"}).then(b => {
                            let c = b.data.find(e => e.id === data.handleState);
                            if (c) {
                                data.state = c.dictName;
                            }
                            current.id = id;
                            current.isLoad = true;
                            current.newsInfo = data;
                        });
                    });
                } else {
                    current.id = id;
                    current.isLoad = true;
                    current.error = true;
                    current.msg = msg;
                }
            });
        }
    }
}

export default NewsService;